<!DOCTYPE html>
<html>
  <head>
    <title>CanvasCircles - Leaflet</title>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />

    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A==" crossorigin="" />
    <script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js" integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA==" crossorigin=""></script>

    <style>
      html,
      body {
        height: 100%;
        margin: 0;
      }
      #map {
        width: 600px;
        height: 400px;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>

    <script type="text/javascript">
      var map = L.map('map', {
        center: [0, 0],
        zoom: 0
      })

      L.GridLayer.CanvasCircles = L.GridLayer.extend({
        createTile: function (coords) {
          var tile = document.createElement('canvas')

          var tileSize = this.getTileSize()
          tile.setAttribute('width', tileSize.x)
          tile.setAttribute('height', tileSize.y)

          var ctx = tile.getContext('2d')

          // https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/arc
          ctx.arc(tileSize.x / 2, tileSize.x / 2, 4 + coords.z * 4, 0, 2 * Math.PI, false)
          ctx.fill()

          return tile
        }
      })

      L.gridLayer.canvasCircles = function (opts) {
        return new L.GridLayer.CanvasCircles(opts)
      }

      map.addLayer(L.gridLayer.canvasCircles())
    </script>
  </body>
</html>
